package com.ocom.human.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.human.EntitySaasInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.human.dao.IDaoSaasInfo;
import com.ocom.human.service.SaasInfoService;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SaasInfoServiceImpl extends ServiceImpl<IDaoSaasInfo, EntitySaasInfo> implements SaasInfoService {

    @Autowired
    private IDaoSaasInfo iDaoSaasInfo;


    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public EntitySaasInfo getSaas(Integer saasNo) {
        QueryWrapper<EntitySaasInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("saas_no",saasNo);
        return iDaoSaasInfo.selectOne(queryWrapper);
    }

    @DataSourceAspect(type= DataSourceEnum.MAIN_DB,isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public List<EntitySaasInfo> getSaasList() {
        QueryWrapper<EntitySaasInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByAsc("saas_no");
        return iDaoSaasInfo.selectList(queryWrapper);
    }
}
